package OptimalAlgorithm.PrefixSum;

import java.util.Scanner;

public class One_dimensional_PrefixSum_Template {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = new int[n + 1];//n + 1 可以避免处理边界情况
            for (int i = 1; i < n + 1; i++) {
                a[i] = in.nextInt();
            }
            long[] dp = new long[n + 1];//long防溢出
            dp[0] = 0;
            for (int j = 1; j < n + 1; j++) {
                dp[j] = a[j] + dp[j - 1];
            }
            for (int i = 0; i < m; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                System.out.println(dp[r] - dp[l - 1]);
            }
        }
    }
/*    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = new int[n];
            long[] dp = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                if(i == 0){
                    dp[0] = a[0];
                }else {
                    dp[i] = a[i] + dp[i - 1];
                }
            }
            for (int i = 0; i < m; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                if(l == 1){
                    System.out.println(dp[r - 1]);
                }else {
                    System.out.println(dp[r - 1] - dp[l - 2]);
                }
            }
        }
    }*/
}
